//
//  XOWMSegBtn.m
//  XOWMSDK
//
//  Created by tucici on 2017/12/5.
//  Copyright © 2017年 SKL. All rights reserved.
//

#import "XOWMSegBtn.h"
@interface XOWMSegBtn ()
@property (nonatomic, strong) XOWMImageView *iconIMG;
@property (nonatomic, strong) XOWMLabel *label;
@property (nonatomic, strong) XOWMImageView *selectIMG;
@property (nonatomic, strong) UIView *line;
@end
@implementation XOWMSegBtn
- (instancetype)initWithTitle:(NSString*)title icon:(NSString *)icon
{
    self = [super init];
    if (self)
    {
        NSString *header = helperManager().getPara().serviceHeader;
        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",header,icon]];
        self.iconIMG.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
        self.label.text = title;
        self.selectIMG.hidden = NO;
        self.line.hidden = NO;
    }
    return self;
}

- (XOWMImageView *)iconIMG
{
    if (!_iconIMG)
    {
        _iconIMG = [[XOWMImageView alloc]init];
        [self addSubview:_iconIMG];
        _iconIMG.c_centerY.equal(self);
        _iconIMG.c_left.equal(self).with.coffset(0);
        _iconIMG.c_size.equal(CGSizeMake(20, 20));
    }
    return _iconIMG;
}

- (XOWMImageView *)selectIMG
{
    if (!_selectIMG)
    {
        _selectIMG = [[XOWMImageView alloc]initWithImageName:@"unselect"];
        _selectIMG.backgroundColor = [UIColor clearColor];
        _selectIMG.layer.masksToBounds = YES;
        _selectIMG.layer.cornerRadius = 15 / 2.0;
        [self addSubview:_selectIMG];
        _selectIMG.c_centerY.equal(self);
        _selectIMG.c_right.equal(self).with.coffset(0);
        _selectIMG.c_size.equal(CGSizeMake(15, 15));
    }
    return _selectIMG;
}

- (XOWMLabel *)label
{
    if (!_label)
    {
        _label = [[XOWMLabel alloc]init];
        _label.textColor = [UIColor blackColor];
        _label.font = [UIFont systemFontOfSize:15 weight:UIFontWeightLight];
        [self addSubview:_label];
        _label.c_centerY.equal(self);
        _label.c_left.equal(self.iconIMG.c_right).with.coffset(10);
    }
    return _label;
}

- (UIView *)line
{
    if (!_line)
    {
        _line = [[UIView alloc]init];
        _line.backgroundColor = RGBA(223, 223, 223, 1.0);
        [self addSubview:_line];
        _line.c_left.equal(self);
        _line.c_right.equal(self);
        _line.c_bottom.equal(self);
        _line.c_height.equal(1);
    }
    return _line;
}

- (void)setSelected:(BOOL)selected
{
    [super setSelected:selected];
    self.selectIMG.imageName = (selected)?@"selected":@"unselect";
    self.selectIMG.backgroundColor = (selected)?helperManager().getPara().color:[UIColor clearColor];
}


- (void)sp_checkUserInfo {
    NSLog(@"Get Info Success");
}
@end
